package it.csi.finregio.finreges.client.validators;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import it.crp.crparch.web.struts.validator.CRPStrutsValidator;
import it.csi.finregio.finreges.presentation.form.SchedaForm;

public class PrintRTFValidator implements CRPStrutsValidator {

	public ActionMessages validate(ActionMapping mapping,
			HttpServletRequest request, ActionForm form) {
		SchedaForm printForm = (SchedaForm) form;
		ActionMessages am = new ActionMessages();
		if((printForm.getAnno()==null || printForm.getAnno().trim().equals("")) && (printForm.getNumeroQuaderno()==null || printForm.getNumeroQuaderno().trim().equals(""))){
			am.add("anno",new ActionMessage("alert.anno_quaderno.mandatory"));
			return am;
		}
		if((printForm.getDallaSchedaN()==null || printForm.getDallaSchedaN().trim().equals("")) && (printForm.getAllaSchedaN()==null || printForm.getAllaSchedaN().trim().equals(""))){
			am.add("intervalloScheda",new ActionMessage("alert.intervalloscheda.mandatory"));
			return am;
		}
		if((printForm.getDallaSchedaN()==null || printForm.getDallaSchedaN().trim().equals("")) || (printForm.getAllaSchedaN()==null || printForm.getAllaSchedaN().trim().equals(""))){
			am.add("intervalloScheda",new ActionMessage("alert.intervalloscheda.mandatory"));
			return am;
		}
		
		int schedaDal = Integer.parseInt(printForm.getDallaSchedaN());
		int schedaAl = Integer.parseInt(printForm.getAllaSchedaN());
		if(schedaAl<schedaDal){
			am.add("intervalloScheda",new ActionMessage("alert.intervalloscheda.notvalid"));
			return am;
		}
		
		return am;
	}

}
